class MyAssociation extends Association { ... }
synchronized public Object valueForKey(String key) { Object dest = this.destination(); if (key.equals("title")) { return ((MyApplet)dest).getLabel(); } } synchronized public void takeValueForKey(Object value, String key) { Object dest = this.destination(); if (key.equals("title")) { if ((value != null) && !(value instanceof String)) { System.out.println("Object value of wrong type set for key 'title'. Value must be a String."); } else { ((MyApplet)dest).setLabel(((value == null) ? "" : (String)value)); } }
Note that the class of the destination applet (in this example, MyApplet) must be cast.
// fictictious method
public void observeGadget(Object sender, String action) {
if ((sender instanceof Gadget) && action.equals("vacuum")) {
this.invokeAction(action);
}
}